Page({
  data: {
    showMakePhone: false,
    userInfo: {
      avatarUrl: '',
      username: '',
      mobile: '',
      class: '',
      sNumber: '',
      type: 0,
      gender: 0
    },
    menuData: [
      [{
          title: '我的信息',
          tit: '',
          type: 'address',
          Icon: 'user-1',
          url: "/pages/usercenter/person-info/index"
        },
        {
          title: '业务模板',
          tit: '',
          type: 'coupon',
          Icon: 'certificate-1',
          url: "/pages/usercenter/gongdan/exampleList/index"
        }
      ]],
    customerServiceInfo: {},
    currAuthStep: 1,
    showKefu: true,
    versionNo: ''
  },
  //页面加载时，执行函数
  onLoad() {
    this.getVersionInfo();
    console.log("load");
  },
  //页面显示时，执行函数
  onShow() {
    // console.log('info',wx.getStorageSync("userInfo"));

    this.getTabBar().init();
    this.init();
    let info = wx.getStorageSync("userInfo")
    if (info === '') 
    { 
      // wx.navigateTo({
      //   url: '/pages/login/login'
      // });
      return;
    }
    let userInfo = JSON.parse(info)
    console.log(userInfo)
    this.setData({
      "userInfo": userInfo
    })
  },

  //用户下拉刷新时调用
  onPullDownRefresh() {
    this.init();
  },
  //一个初始化函数
  init() {},
  show() {
  },
  //处理菜单项的点击事件，根据点击的菜单类型执行相应操作
  onClickCell(e) {
    // wx.navigateTo({
    //   url: e.currentTarget.dataset.url
    // });
  },

  //用户编辑页面函数
  gotoUserEditPage() {
    const {
      currAuthStep
    } = this.data;
    wx.navigateTo({
      url: '/pages/usercenter/person-info/index'
    });
  },

  //获取小程序版本信息
  getVersionInfo() {
    const versionInfo = wx.getAccountInfoSync();
    const {
      version,
      envVersion = __wxConfig
    } = versionInfo.miniProgram;
    this.setData({
      versionNo: envVersion === 'release' ? version : envVersion,
    });
  },

  onLogoutClick() {
    wx.removeStorageSync('userInfo')
    this.setData({
      userInfo: {
        avatarUrl: '',
        username: '',
        mobile: '',
        class: '',
        sNumber: '',
        type: 0,
        gender: 0
      }
    })
    wx.navigateTo({
      url: '/pages/login/login'
    });
  }
});